package com.lyz.lambdas;

/**
 * @ClassName LambdaDemo1
 * @Description lambda表达式
 * @Author 2214361854
 * @Date 2022/2/21 12:15
 * @Version 1.0
 */
public class LambdaDemo1 {
    public static void main(String[] args) {
        //不能用lambda
        Animal animal = new Animal(){
            @Override
            public void run() {
                System.out.println("乌龟跑的慢~~~");
            }
        };
        animal.run();

        System.out.println("==================");

        //简化写法
        Swimming s1 = () -> {
            System.out.println("老师游泳");
        };
        go(s1);
        System.out.println("===================");

        //入参写法
        go(() -> {
            System.out.println("学生游泳");
        });
    }
    public static void go(Swimming s){
        System.out.println("开始");
        s.swim();
        System.out.println("结束");
    }
}
abstract class Animal{
    public abstract void run();
}

/**
 * 函数式接口：必须是接口，且接口中仅有一个抽象方法的形式
 * 注解：@FunctionalInterface
 */
@FunctionalInterface
interface Swimming{
    void swim();
}